package com.song.api.controller.files.fallbacks;

import com.song.api.controller.files.FileUploaderControllerApi;
import com.song.grace.result.GraceJSONResult;
import com.song.grace.result.ResponseStatusEnum;
import com.song.pojo.bo.NewAdminBO;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class FileFallbackFactor implements FallbackFactory<FileUploaderControllerApi> {

    @Override
    public FileUploaderControllerApi create(Throwable throwable) {
        return new FileUploaderControllerApi() {
            @Override
            public GraceJSONResult uploadFace(String userId, MultipartFile file) throws Exception {
                return GraceJSONResult.errorCustom(ResponseStatusEnum.SYSTEM_ERROR_FEIGN);
            }

            @Override
            public GraceJSONResult uploadSomeFiles(String userId, MultipartFile[] files) throws Exception {
                return GraceJSONResult.errorCustom(ResponseStatusEnum.SYSTEM_ERROR_FEIGN);
            }

            @Override
            public GraceJSONResult uploadToGridFS(NewAdminBO newAdminBO) throws Exception {
                return GraceJSONResult.errorCustom(ResponseStatusEnum.SYSTEM_ERROR_FEIGN);
            }

            @Override
            public void readInGridFS(String faceId, HttpServletRequest request, HttpServletResponse response) throws Exception {

            }

            @Override
            public GraceJSONResult readFace64InGridFS(String faceId) {
                String base64Face = new String();
                return GraceJSONResult.ok(base64Face);
            }
        };
    }
}
